<%@page import="com.railway.news.model.*"%>
<%@ page import="com.railway.common.constants.SysConstant"%>
<%@page import="java.util.List"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
	<head>

		<title><%=NewsColums.TABLE_ALIAS%>前台列表</title>
		<%@ include file="/commons/listcssjs.jsp"%>
	</head>
	<body> <c:if test="${sessionScope.username=='admin'}"> 
		<div class="queryPanel">
			<fieldset style="width: 780px">
		
				<form name="form1" id="form1" action="${ctx}/news/Category/save.do" method="post">
					<table>
						<tr>
							<td class="tdLabel"><%=CategoryColums.ALIAS_NAMES%></td>
							<td>
								<input id="names" name="names" value="" type="text"
									class="easyui-validatebox" />
								<input id="publicType" name="publicType" type="hidden"
									value="${param.title}">
								<input id="returnUrl" name="returnUrl" type="hidden" 	value="${ctx}/news/News/getNewsByTitle.do?title=${param.title}" >
							</td>
							<td class="tdLabel"><%=CategoryColums.ALIAS_ORDER_NO%></td>
							<td>
								<input id="orderNo" name="orderNo" value="" type="text"
									class="easyui-validatebox" />
							</td>
							<td class="tdLabel"><%=CategoryColums.ALIAS_CA_TYPES%></td>
							<td>
								<select id="caTypes" name="caTypes">
									<option value="TXT">
										文字
									</option>
									<option value="IMGX">
										大图片
									</option>
										<option value="IMGX">
										小图片
									</option>
								</select>
							</td>
							<td class="tdLabel">
								维护负责人
							</td>
							<td>
								<input readonly value="" id="maintainer" name="maintainer" maxlength="200" class=""
									onclick="javascript:openDeptUserList('M');" />
							
								<input type="hidden" name="maintainerid" />
							</td>
						</tr>
						<tr>
							<td class="tdLabel">
								<%=CategoryColums.ALIAS_PUBLIC_TYPE%>
							</td>
							<td>
								<select id="state" name="state" >
									<option value="0">
										是
									</option>
									<option value="1">
										否
									</option>

								</select>
							</td>
							<td class="tdLabel">
								可访问人
							</td>
							<td>
					            <input value=""
									onclick="javascript:openDeptUserList('V');" id="visitor"
									name="visitor" maxlength="200" class="" />
						
								<input type="hidden" name="visitorid" />
							</td>
							<td class="tdLabel"><%=CategoryColums.ALIAS_IS_CHECK%></td>
							<td>
								<select id="isCheck" name="isCheck">
									<option value="N">
										否
									</option>
									<option value="Y">
										是
									</option>
								</select>
							</td>


							<td class="tdLabel">
								审核人
							</td>
							<td>
							<input value="" id="checker" name="checker" maxlength="200"
									onclick="javascript:openDeptUserList('C');" />
								
								<input type="hidden" name="checkerid" />
							</td>
							<td colspan=2>
								<input value="" type="hidden" id="title" name="title"
									maxlength="200" class="" />
								<input type=button onclick="saveTitle()" value="新增栏目">
							</td>
						</tr>
					</table>
				</form>
			</fieldset>
		</div>
		<br>
		<br>
		<br>
		</c:if>
		 
		<div id="show" style="width: 1000px; padding: 0px;">
			<c:forEach items="${requestScope.catList}" var="item">
			<c:if test="${sessionScope.username=='admin'||fn:indexOf(sessionScope.userCates,item.id)>=0}"> 
				<form id="${item.id}Form" name="${item.id}Form" action=""
					method="post" style="display: inline;">
			
					<table id="${item.id}Table" name="${item.id}Table"
						class="listTable">
						<th colspan=5 align="left">
							&nbsp;
							<span> <a href="${ctx}/news/News/list.do?catId=${item.id}">${item.names}</a>
							</span>&nbsp;&nbsp;&nbsp;&nbsp;
							<span><c:if test="${sessionScope.username=='admin'}"> 
							       <input type=button value="编辑栏目" onclick='updateCat("${item.id}")'>
							       &nbsp;&nbsp;&nbsp;<input
									onclick='if(confirm("确定删除?")==true){return 		  removeCat("${item.id}");}else{return false;}' type=button value="删除栏目">
									</c:if>
							</span>
						</th>
						<tr>
							<td colspan=4>
								<a id="btnadd" class="l-btn l-btn-plain" style="float: left;"
									href="javascript:void(0)" onclick='addNews("${item.id}");return false;' > <span
									class="l-btn-left"> <span style="padding-left: 20px;"
										class="l-btn-text icon-create">新增</span>
								</span>
								</a>
								<div class="datagrid-btn-separator">
								</div>
							</td>
						</tr>
						<tr>
							<td class="title">
								新闻标题
							</td>
							<td class="title">
								发布人
							</td>
							<td class="title">
								发布时间
							</td>
							<td class="title">
								操作
							</td>
						</tr>
						<c:if test="${item.newsList!=null}">
							<c:forEach items="${item.newsList}" var="temp">
								<tr>
									<td>
										${temp.title}
									</td>
									<td>
										${temp.authorId}
									</td>
									<td>
										${temp.createTimeString}
									</td>
									<td><c:if test="${temp.authorId==sessionScope.userId||sessionScope.username=='admin'}">
										<a href="javascript:void(0)" onclick='updateNews("${temp.id}");return false;' >修改</a>
										<a href="javascript:void(0)" onclick='removeNews("${temp.id}");return false;' >删除</a>
									   </c:if>
									</td>
								<tr>
							</c:forEach>
						</c:if>
					</table>
				</form>
				  <br>
				</c:if>
		 	</c:forEach>

		</div>
		
	</body>
	<script>
$(function(){
     $.get("/system/SysUser/getUserDept.do", {	            
                Action:"get",Name:"user01"}, function (data, textStatus){		
                var zNodes = eval(data);              
                $.fn.zTree.init($("#treeDemo"), setting, zNodes);                
	 });
    // $.get('${ctx}/news/News/getNewsByTitle.do?title=${param.title}&t='+Math.random(), function(josn){
    //   josn = josn.replace(new RegExp("null","gm"),'""');
     //  var mydata = eval("("+josn+")");
     //   for(var p in mydata){  
     //    var cat=mydata[p]; 
    //     var htmlStr=createTable(cat);
	//	 $("#show").html(htmlStr);
	  
		
    //    } 
	     
	// }) ;  
    
});
function createTable(cat){
       var  htmlStr = '<form id="'+cat.id+'Form" name='+cat.id+'Form"  action="" method="post" style="display: inline;">';
		    htmlStr+='<table id="'+cat.id+'Table" name='+cat.id+'Table" class="listTable"   >';
			htmlStr+='<th colspan=5 align="left" >&nbsp;<span><a href="javascript:void(0)" onclick=addNews("'+cat.id+'")>'+cat.names+'</a></span>&nbsp;&nbsp;&nbsp;&nbsp;<span> <input  type=button value="编辑栏目" >&nbsp;&nbsp;&nbsp;<input  type=button value="删除栏目" ></span> </th>'; 
		 	htmlStr+='<tr><td colspan=4>';
		  
			htmlStr+='<a id="btnadd" class="l-btn l-btn-plain" style="float: left;" href="javascript:void(0)" onclick=addNews("'+cat.id+'") >'; 
			htmlStr+='<span class="l-btn-left"><span style="padding-left: 20px;"';
			htmlStr+='class="l-btn-text icon-create">新增</span> </span> </a>';
			htmlStr+='<div class="datagrid-btn-separator"></div>';
			htmlStr+='</td>';
			htmlStr+='</tr>';
			htmlStr+='<tr>'; 
			htmlStr+='<td class="title">新闻标题</td>';
			htmlStr+='<td class="title">发布人</td>';
			htmlStr+='<td class="title">发布时间</td>';
			htmlStr+='<td class="title">操作</td>';
			htmlStr+='</tr>';  
			if(cat.newsList!=''){
			    var newsList=cat.newsList;
			      for(var j=0;j<newsList.length;j++){
			         content='<tr>'; 
					 content+='<td >'+newsList[j].title+'</td>'; 
					 content+='<td >'+newsList[j].urls+'</td>';
					 content+='<td >'+newsList[j].urls+'</td>';
					 content+='<td >'+newsList[j].urls+'</td>';
					 content+='<td > <a href="javascript:void(0)" onclick=updateNews("'+newsList[j].id+'") >修改</a> <a href="javascript:void(0)" onclick=removeNews("'+newsList[j].id+'") >删除</a></td>';
							
					 content='<tr>';
				 }
			}
			htmlStr+= '</table>';
			htmlStr+= '</form>';
			return htmlStr;
}
function saveTitle(){  
    $('#form1').submit();
  
}
function addNews(catId){
     
    window.location.href="${ctx}/news/News/create.do?catId="+catId+"&returnUrl=${ctx}/news/News/getNewsByTitle.do?title=${param.title}" ; 
}
function updateNews(newsId){
       window.location.href="${ctx}/news/News/edit.do?id="+newsId+"&returnUrl=${ctx}/news/News/getNewsByTitle.do?title=${param.title}" ; 

    
}
function removeNews(newsId){
   window.location.href="${ctx}/news/News/remove.do?id="+newsId+"&returnUrl=${ctx}/news/News/getNewsByTitle.do?title=${param.title}" ; 
}
function updateCat(catId){
   window.location.href="${ctx}/news/Category/edit.do?id="+catId+"&returnUrl=${ctx}/news/News/getNewsByTitle.do?title=${param.title}" ; 
}

function removeCat(catId){

   window.location.href="${ctx}/news/Category/remove.do?id="+catId+"&returnUrl=${ctx}/news/News/getNewsByTitle.do?title=${param.title}" ; 
}
 function openDeptUserList(type){ 
		      	          
	        var width = 800;
            var height =350;
            var url='${ctx}/system/SysUser/showDeptUserList.do?<%=SysConstant.USER_CALL_TYPES%>=<%=SysConstant.USER_CALL_TYPES_CATEGORY%>&userTypes='+type; //要打开的窗口   
            var returnVal =  window.showModalDialog(url, window.document, "dialogWidth="+width+"px;dialogHeight="+height+"px;status:0;scroll:no");   
            if(returnVal == undefined) {           
          	   return;           
            }
   
            if(type == 'M'){
                      form1.maintainerid.value = returnVal[0];
                   //   form1.maintainer.value = returnVal[1];
            }else if(type == 'C'){
                      form1.checkerid.value = returnVal[0];
                     // form1.checker.value = returnVal[1];
            }else if(type =='V'){
                      form1.visitorid.value = returnVal[0];
               		//  form1.visitor.value = returnVal[1];
      
           
            }
             
 		  }
	    function openURL(urlstr,width,height){  
      	var url ;
      	if('NewsCategory' == urlstr){
       	  url = '/news/Category/showCategoryTree.do';      
      	}
        
           var returnVal = window.showModalDialog(url, window, "dialogWidth="+width+"px;dialogHeight="+height+"px;status:0;scroll:no");   
           form1.parentId.value = returnVal[0]; 
     
        }  
	    var setting = {
			check: {
				enable: true,
				chkboxType: { "Y" : "ps", "N" : "ps" }
			},
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onCheck: onCheck
			}
		};

		function beforeClick(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.checkNode(treeNode, !treeNode.checked, null, true);
			return false;
		}
		
		function onCheck(e, treeId, treeNode) {

			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
	
			for (var i=0, l=nodes.length; i<l; i++) {
				if(nodes[i].type == 1){
				var tt = nodes[i].id;
		     	form1.permituids.value +=   tt.substring(1,tt.length) + ",";
				v += nodes[i].name + ",";}
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			var cityObj = $("#citySel");
			cityObj.attr("value", v);
		}

		 function showMenu() {
			var cityObj = $("#citySel");
			
			var cityOffset = $("#citySel").offset();
			
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event){
			if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
</script>
</html>
